<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>微刻时光-管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <!--[if lt IE 9]>
    <script src="/static/admin/html5.min.js"></script>
    <script src="/static/admin/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="/static/admin/css/login.css" media="all">
</head>
<body>
<div class="main-body">
    <div class="login-main">
        <div class="login-top">
            <span>微刻时光</span>
            <span class="bg1"></span>
            <span class="bg2"></span>
        </div>
        <form class="layui-form login-bottom">
            <div class="center">
                <div class="item">
                    <span class="icon icon-2"></span>
                    <input type="text" name="username" lay-verify="required"  placeholder="请输入登录账号" maxlength="24"/>
                </div>

                <div class="item">
                    <span class="icon icon-3"></span>
                    <input type="password" name="password" lay-verify="required"  placeholder="请输入密码" maxlength="20">
                    <span class="bind-password icon icon-4"></span>
                </div>

                <div id="validatePanel" class="item" style="width: 137px;">
                    <input type="text" name="captcha" placeholder="请输入验证码" maxlength="4">
                    <img id="refreshCaptcha" class="validateImg"  src="/static/admin/images/captcha.jpg" >
                    <input type="hidden" value="{{.yzm.Id}}" id="captcha_id" name="captcha_id">
                </div>

            </div>
            <div class="tip">
                <span class="icon-nocheck"></span>
                <span class="login-tip">保持登录</span>
                <a href="javascript:" class="forget-password">忘记密码？</a>
            </div>
            <div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
                <button class="login-btn" lay-submit="" lay-filter="login">立即登录</button>
            </div>
        </form>
    </div>
</div>
<div class="footer">
    ©版权所有 2020-2021 微刻时光工作室<span class="padding-5">|</span><a target="_blank" href="http://beian.miit.gov.cn/">吉ICP备20001019号-1</a>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>

    layui.use(['form','jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

        //登录页面验证码
        var yzm = {{.yzm.Bs64}}
        $("#refreshCaptcha").attr('src',yzm);

        //点击图片刷新验证码
        $("#refreshCaptcha").click(function(){
            $.ajax({
                url:"/sys/ChangeCaptcha",
                data:{},
                type:"GET",
                success:function (data) {
                    var code = data["Code"];
                    if(code != 200){  // 发生错误了
                        layer.msg(data["msg"])
                    }
                    else {
                        var base64_value = data["Bs64"];
                        var Id = data["Id"];
                        console.log(base64_value);

                        $("#refreshCaptcha").attr('src',base64_value);
                        $("#captcha_id").attr('src',Id);

                    }
                }
            })
        });


        // 登录过期的时候，跳出ifram框架
        if (top.location != self.location) top.location = self.location;

        $('.bind-password').on('click', function () {
            if ($(this).hasClass('icon-5')) {
                $(this).removeClass('icon-5');
                $("input[name='password']").attr('type', 'password');
            } else {
                $(this).addClass('icon-5');
                $("input[name='password']").attr('type', 'text');
            }
        });

        $('.icon-nocheck').on('click', function () {
            if ($(this).hasClass('icon-check')) {
                $(this).removeClass('icon-check');
            } else {
                $(this).addClass('icon-check');
            }
        });

        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            if (data.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password == '') {
                layer.msg('密码不能为空');
                return false;
            }
            if (data.captcha == '') {
                layer.msg('验证码不能为空');
                return false;
            }

            $.ajax({
                url:"/sys/doLogin",
                data:{
                    username:data.username,
                    password:data.password,
                    captcha:data.captcha,
                    captcha_id:$("#captcha_id").val()
                },
                type:"POST",
                success:function (data) {
                    var code = data["code"];
                    if(code != 200){
                        layer.msg(data["msg"])
                    }
                    else {
                        layer.msg('登录成功', function () {
                            window.location.href = '/sys/main';
                        });
                    }
                }
            })



            return false;
        });
    });
</script>
</body>
</html>